55. 跳跃游戏
为保证权益,题目请参考 55. 跳跃游戏(From LeetCode).
解决方案1
CPP
C++
//
// Created by lenovo on 2020-09-19.
//
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
/**
* @brief solution
*/
class Solution {
public:
/**
* @brief core function
* @param nums
* @return
*/
bool canJump(vector<int> &nums) {
int m = 0; ///< the fastest position coule be.
for (int i = 0; i < nums.size(); i++) {
if (i <= m) {
m = max(m, i + nums[i]);
}
}
return m>= nums.size()-1;
}
};
int main() {
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36